import Vue from 'vue'
import App from './App.vue'
import './plugins/element.js'


import router from './router'
import store from './store'

Vue.config.productionTip = false

let vm = null 
vm = new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

console.log(vm);
window.vm = vm


import { registerMicroApps, start } from 'qiankun';

//封装一个getActiveRule方法-支持hash路由
const getActiveRule = (hash) => (location) => location.hash.startsWith(hash);

//子应用列表
let apps = [
  {
    name:'child-app1',
    entry:'http://localhost:9091',//子应用的地址，这里演示是本地启动的地址。
    container:'#child-app1',//子应用的容器节点的选择器（vue一般为app）
    activeRule:  getActiveRule('#/child-app1'),//访问子应用的规则，比如：主应用为localhost:8081，那访问该子应用的url应为localhost:8081/#/subapp
    props: { 
      data : {
        root:vm, 
        store, 
        router,
        callback:(e)=>{
          console.log("child-app1 挂载回调成功！",e);
          (e.components ||[]).forEach(module=>{
            console.log(module, module.name,  module.component);
            const name = module.name
            name && Vue.component(name, module.component.default)
          });
          store.commit('setApp1Callback',true)
        } 
      } 
    }
  },
  {
    name: 'child-app2',
    entry: 'http://localhost:9092',
    container: '#child-app2',
    activeRule: getActiveRule('#/child-app2'),
  }
]

//注册子应用
registerMicroApps(apps);

//启动
start({
    experimentalStyleIsolation:true,
    strictStyleIsolation: true,
});





